import 'package:dio_log/dio_log.dart';
import 'package:flutter/material.dart';
import 'package:flutterapp/Base/router/RouterConfig.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:shake/shake.dart';

class ShakeManager {
  ShakeDetector detector;
  static ShakeManager _shakeManager;
  static const SHAKE_LIMIT = 3;
  int shakeNum = 0;

  ShakeManager._() {
    detector = ShakeDetector.waitForStart(onPhoneShake: () {
      Fluttertoast.showToast(msg: "shake ${++shakeNum} times");
      if (shakeNum == SHAKE_LIMIT) {
        MyNavigatorObserver.getInstance().navigator.push(MaterialPageRoute(
              builder: (context) => HttpLogListWidget(),
            ));
        shakeNum = 0;
      }
    });
  }

  factory ShakeManager.getInstance() {
    if (_shakeManager == null) {
      _shakeManager = ShakeManager._();
    }
    return _shakeManager;
  }

  startListening() {
    detector.startListening();
  }

  stopListening() {
    detector.stopListening();
  }
}
